package com.mc.mcgoweb.thread;


/**
 *包装模式
 */
public abstract class TemplateMethod {
    public final void print(String msg) {
        System.out.println("===============");
        wrapPrint(msg);
        System.out.println("===============");

    }

    private static int threadInitNumber;

    private static synchronized int nextThreadNum() {
        return threadInitNumber++;
    }

    protected abstract void wrapPrint(String msg);

    public static void main(String[] args) {
        int i = nextThreadNum();
        Thread thread = new Thread();
        thread.start();
        TemplateMethod templateMethod = new TemplateMethod() {
            @Override
            protected void wrapPrint(String msg) {
                System.out.println("----------" + msg + "-----------");
            }
        };
        TemplateMethod templateMethod1 = new TemplateMethod() {
            @Override
            protected void wrapPrint(String msg) {
                System.out.println("+++++++++++" + msg + "+++++++++++");
            }
        };
        templateMethod.print("hello");
        templateMethod1.print("hello");

    }
}
